package net.hn.hnms.biz.training.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.training.request.PersonnelCertificateReq;
import net.hn.hnms.biz.training.service.PersonnelCertificateService;
import net.hn.hnms.biz.training.vo.PersonCountVO;
import net.hn.hnms.biz.training.vo.PersonnelCertificateVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(value = "全员持证模块", tags = {"全员持证"})
@RestController
@RequestMapping("/certificate")
public class PersonnelCertificateController  extends BaseController {


    @Autowired
    private PersonnelCertificateService personnelCertificateService;


    @ApiOperation("煤矿其他从业人员导入")
    @SaCheckPermission("training:certificate:importOther")
    @PostMapping("/importOther")
    @Log(title = "煤矿其他从业人员导入", businessType = BusinessType.IMPORT)
    public R<Void> importOtherResult(@RequestPart MultipartFile file) {
        personnelCertificateService.importResult(file,"4");
        return R.ok();
    }


    /**
     * 安全生产管理人员持证明细下载
     */
    @ApiOperation("安全生产管理人员持证明细下载")
    @SaCheckPermission("training:certificate:downloadpordManageUser")
    @GetMapping("/downloadpordManageUser")
    @Log(title = "安全生产管理人员持证明细下载", businessType = BusinessType.EXPORT)
    public void downloadAppraiserTraining(HttpServletResponse response) {
        personnelCertificateService.downloadpordManageUser(response);
    }
    /**
     * 五职矿长与副总工程师持证明细导入模板下载
     */
    @ApiOperation("五职矿长与副总工程师持证明细模板下载")
    @SaCheckPermission("training:certificate:downloadbarmasterUser")
    @GetMapping("/downloadbarmasterUser")
    @Log(title = "五职矿长与副总工程师持证明细模板下载", businessType = BusinessType.EXPORT)
    public void downloadbarmasterUser(HttpServletResponse response) {
        personnelCertificateService.downloadbarmasterUser(response);
    }
    /**
     * 特种作业持证明细模板下载
     */
    @ApiOperation("特种作业持证明细模板下载")
    @SaCheckPermission("training:certificate:downloadTrinidadAndTobago")
    @GetMapping("/downloadTrinidadAndTobago")
    @Log(title = "特种作业持证明细模板下载", businessType = BusinessType.EXPORT)
    public void downloadTrinidadAndTobago(HttpServletResponse response) {
        personnelCertificateService.downloadTrinidadAndTobago(response);
    }
    /**
     * 五职矿长与副总工程师持证明细导入模板下载
     */
    @ApiOperation("煤矿其他从业人员模板下载")
    @SaCheckPermission("training:certificate:downloadotherStaffsUser")
    @GetMapping("/downloadotherStaffsUser")
    @Log(title = "煤矿其他从业人员模板下载", businessType = BusinessType.EXPORT)
    public void downloadotherStaffsUser(HttpServletResponse response) {
        personnelCertificateService.downloadotherStaffsUser(response);
    }

    /**
     * 五职矿长与副总工程师持证明细导入
     */
    @ApiOperation("五职矿长与副总工程师持证明细导入")
    @SaCheckPermission("training:certificate:importbarmasterUser")
    @PostMapping("/importbarmasterUser")
    @Log(title = "五职矿长与副总工程师持证明细导入", businessType = BusinessType.IMPORT)
    public R<Void> importResultbarmasterUser( @RequestPart MultipartFile file) {
        personnelCertificateService.importResult(file,"1");
        return R.ok();
    }

    /**
     * 安全生产管理人员持证明细导入
     */
    @ApiOperation("安全生产管理人员持证明细导入")
    @SaCheckPermission("training:certificate:importpordManageUser")
    @PostMapping("/importpordManageUser")
    @Log(title = "安全生产管理人员持证明细导入", businessType = BusinessType.IMPORT)
    public R<Void> importResultpordManageUser( @RequestPart MultipartFile file) {
        personnelCertificateService.importResult(file,"2");
        return R.ok();
    }

    /**
     * 特种作业持证明细导入
     * @param file
     * @return
     */
    @ApiOperation("特种作业持证明细导入")
    @SaCheckPermission("training:certificate:importOtherTrinidadAndTobago")
    @PostMapping("/importOtherTrinidadAndTobago")
    @Log(title = "特种作业持证明细导入", businessType = BusinessType.IMPORT)
    public R<Void> importTrinidadAndTobago(@RequestPart MultipartFile file) {
        personnelCertificateService.importResult(file,"3");
        return R.ok();
    }

    /**
     * 汇总
     * @return
     */
    @ApiOperation("汇总")
    @GetMapping("count")
    public R<List<PersonCountVO>> count(){

        return R.ok(personnelCertificateService.PersonCount());
    }

    /**
     * 汇总下载
     */
    @ApiOperation("汇总下载")
    @SaCheckPermission("training:certificate:downloadCount")
    @GetMapping("/downloadCount")
    @Log(title = "汇总下载", businessType = BusinessType.EXPORT)
    public void downloadTemplate(HttpServletResponse response) {
        personnelCertificateService.downloadCount(response);
    }



    /**
     * 新增
     */
    @ApiOperation("新增全员持证")
    @SaCheckPermission("training:certificate:add")
    @PostMapping("/add")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody PersonnelCertificateReq personnelCertificateReq) {
        return toAjax(personnelCertificateService.insert(personnelCertificateReq));
    }

    /**
     * 删除
     */
    @ApiOperation("删除全员持证")
    @SaCheckPermission("training:certificate:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("delete")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        personnelCertificateService.deleteBatch(idList);
        return R.ok();
    }


    /**
     * 修改
     */
    @ApiOperation("修改全员持证")
    @SaCheckPermission("training:certificate:update")
    @PutMapping("/update")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody PersonnelCertificateReq planMining) {
        personnelCertificateService.updateById(planMining);
        return R.ok();
    }




    /**
     * 获取列表
     */
    @ApiOperation("获取分页列表")
//    @SaCheckPermission("plan:sale:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<PersonnelCertificateVo>> page(PersonnelCertificateReq planMining, PageQuery pageQuery) {
        return R.ok(personnelCertificateService.selectPageList(planMining, pageQuery));
    }


    /**
     * 获取 列表
     */
    @ApiOperation("获取列表")
//    @SaCheckPermission("plan:sale:list")
    @GetMapping("/list")
    public R<List<PersonnelCertificateVo>> list(PersonnelCertificateReq planMining) {
        return R.ok(personnelCertificateService.selectList(planMining));
    }

    /**
     * 获取 计划详情
     */
    @ApiOperation("获取详情")
//    @SaCheckPermission("plan:sale:detail")
    @GetMapping("/{id}")
    public R<PersonnelCertificateVo> detail(@PathVariable("id") String id) {
        return R.ok(personnelCertificateService.selectDetailById(id));
    }
}
